@@ -39,6 +39,15 @@ class JobsController < ApplicationController |
||
39 | 39 |
end |
40 | 40 |
end |
41 | 41 |
|
42 |
+ def retry_queued |
|
43 |
+ @jobs = Delayed::Job.awaiting_retry.update_all(run_at: Time.zone.now) |
|
44 |
+ |
|
45 |
+ respond_to do |format| |
|
46 |
+ format.html { redirect_to jobs_path, notice: "Queued jobs getting retried." } |
|
47 |
+ format.json { head :no_content } |
|
48 |
+ end |
|
49 |
+ end |
|
50 |
+ |
|
42 | 51 |
def destroy_failed |
43 | 52 |
Delayed::Job.where.not(failed_at: nil).delete_all |
44 | 53 |
|
@@ -80,6 +80,10 @@ |
||
80 | 80 |
<span class="glyphicon glyphicon-trash"></span> Remove failed jobs |
81 | 81 |
<% end %> |
82 | 82 |
|
83 |
+ <%= link_to retry_queued_jobs_path, class: "btn btn-default", method: :post do %> |
|
84 |
+ <span class="glyphicon glyphicon-refresh"></span> Retry queued jobs |
|
85 |
+ <% end %> |
|
86 |
+ |
|
83 | 87 |
<%= link_to destroy_all_jobs_path, class: "btn btn-default", method: :delete, data: { confirm: "Are you sure you want to delete ALL pending jobs for all Huginn users?" } do %> |
84 | 88 |
<span class="glyphicon glyphicon-remove"></span> Remove all jobs |
85 | 89 |
<% end %> |
@@ -12,7 +12,7 @@ Delayed::Worker.logger = Rails.logger |
||
12 | 12 |
|
13 | 13 |
class Delayed::Job |
14 | 14 |
scope :pending, ->{ where("locked_at IS NULL AND attempts = 0") } |
15 |
- scope :awaiting_retry, ->{ where("failed_at IS NULL AND attempts > 0") } |
|
15 |
+ scope :awaiting_retry, ->{ where("failed_at IS NULL AND attempts > 0 AND locked_at IS NULL") } |
|
16 | 16 |
scope :failed, -> { where("failed_at IS NOT NULL") } |
17 | 17 |
end |
18 | 18 |
|
@@ -63,6 +63,7 @@ Huginn::Application.routes.draw do |
||
63 | 63 |
collection do |
64 | 64 |
delete :destroy_failed |
65 | 65 |
delete :destroy_all |
66 |
+ post :retry_queued |
|
66 | 67 |
end |
67 | 68 |
end |
68 | 69 |
|
@@ -92,4 +92,18 @@ describe JobsController do |
||
92 | 92 |
expect(Delayed::Job.find(@running.id)).to be |
93 | 93 |
end |
94 | 94 |
end |
95 |
+ |
|
96 |
+ describe "POST retry_queued" do |
|
97 |
+ before do |
|
98 |
+ @not_running = Delayed::Job.create(run_at: Time.zone.now - 1.hour) |
|
99 |
+ @not_running.update_attribute(:attempts, 1) |
|
100 |
+ sign_in users(:jane) |
|
101 |
+ end |
|
102 |
+ |
|
103 |
+ it "run the queued job" do |
|
104 |
+ expect(Delayed::Job.last.run_at.to_s).not_to eq(Time.zone.now.to_s) |
|
105 |
+ post :retry_queued |
|
106 |
+ expect(Delayed::Job.last.run_at.to_s).to eq(Time.zone.now.to_s) |
|
107 |
+ end |
|
108 |
+ end |
|
95 | 109 |
end |